
from weibo_api.user_api import get_user_info_api
from domain.UserInfoDB import UserInfoDB
from database.user import insert_user, select_user_id, update_user
from database.common import conn

def get_user_info_and_store(user_id):
    # 先判断数据库是否已经有了这个id的相关信息
    user_info_json = get_user_info_api(user_id)
    user_info_class = UserInfoDB(**user_info_json)
    
    id_result = select_user_id(user_id)
    if id_result == None:
        print("插入")
        insert_user(user_info_class)
    else:
        print("更新")
        update_user(user_info_class)
    conn.commit()
    # print("存储完毕")

